package leetcode;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

/**
 * 描述:530. 二叉搜索树的最小绝对差
 *
 * @author Madison You
 * @created 0:33
 */
public class Easy_530_GetMinimumDifference {
    public static void main(String[] args) {
        TreeNode treeNode = CreateTreeNode.arrayToTreeNode(new Integer[]{236,104,701,null,227,null,911});
        int minimumDifference = new Easy_530_GetMinimumDifference().getMinimumDifference(treeNode);
        System.out.println(minimumDifference);
    }

    int min = Integer.MAX_VALUE;
    TreeNode pre = null;
    public int getMinimumDifference(TreeNode root) {
        back(root);
        return min;
    }

    public void back(TreeNode root) {
        if (root == null) return;
        back(root.left);
        if (pre != null) {
            min = Math.min(min, root.val - pre.val);
        }
        pre = root;
        back(root.right);
    }
}
